// JavaScript Document
TOOLS.ready(function(){
	window.tre = new Ctrace();
	window.tre.traceBgColor = 'blue'
	window.tre.traceFontSize = 20 ; 
	//tre.trace( Ctrace.mkId() , 'blue' )
	//tre.trace( Ctrace.mkId() , 'green' )
	//tre.trace( Ctrace.mkId() , '' ,24,false)
	
	$(window).on('keyup',function(){
		 
	var event=window.event||arguments.callee.caller.arguments[0];
       // mkTrace(event.keyCode+':'+ String.fromCharCode(event.keyCode))
	if(event.keyCode==70){
		  
		
		  
			 try{doll.fullscreen(  (window.parent.document.getElementById('idifr'))  )}catch(e){};
			 doll.fullscreen();
		  
		try{
		window.parent.FastFull()
		console.log('子框控制父框函数FastFull()')
		}catch(e){}
		 
		 
	}
	if(event.keyCode===69){
		    doll.exitFullscreen()
			doll.exitFullscreen( window.parent.document)
			
			// try{ (   window.parent.document  ).webkitCancelFullScreen() }catch(e){console.warn(e)};
			 	
	}	
	if(event.keyCode === 68 ){
		   var arr=['idfps' , 'info'];
		   for(k in arr){	
		   try{	 
		   var d = document.getElementById(arr[k]).style.display ;
		   document.getElementById(arr[k]).style.display = d!== 'none' ? 'none' : 'block';
		   }catch(e){}
		   }
		   window.sta.stop=!window.sta.stop
		   if(window.sta.stop===!true){
		       window.sta.runLoop();
		   }
	}
	
    if(event.keyCode === 190){
        oPlayer.player().currentTime += 10;
    }
    if(event.keyCode === 188){
        oPlayer.player().currentTime -= 10;
    }
	 if(event.keyCode === 38){
		 
		 
		if(oPlayer.player().volume<1.0){
			if(oPlayer.player().volume<0.2 && oPlayer.player().volume > 0.1){
			  oPlayer.player().volume =0.20	
			}else{
            oPlayer.player().volume += 0.1;
			}
		}
		
		//console.log('oPlayer.player().volume:'+oPlayer.player().volume);
		//console.log(oPlayer.player().currentTime+'/'+oPlayer.player().duration)

    }
	
	 if(event.keyCode === 40){
		 if(oPlayer.player().volume>0.1){
         oPlayer.player().volume -= 0.1;}
		 if(oPlayer.player().volume<0.18){
			oPlayer.player().volume -= 0.01; 
			
			if(oPlayer.player().volume < 0.012 ){
				oPlayer.player().volume = 0.0;
			}
		 }
		 console.log('oPlayer.player().volume:'+oPlayer.player().volume);
    }
	if(event.keyCode===77 ){
		oPlayer.player().muted = !oPlayer.player().muted; 		 
	}
	
	//l键设置单曲循环
	if(event.keyCode===76 ){
		if(window.loopworld.Singleloop){
		window.loopworld.Singleloop = false;
		}else{
		window.loopworld.Singleloop = true;	
		}
	    window.tre.traceBgColor = 'blue'
		tre.traceOne( window.loopworld.Singleloop ? '单曲循环' :  '连播',false )
	}
	
	if(event.keyCode==80){
	
		if(! oPlayer.player().paused){
		    oPlayer.player().pause();	
		}else{
		    oPlayer.player().play();	
		}
	}
	if(event.keyCode===82){
		    window.location.reload();
			 try{doll.fullscreen(  (window.parent.document.getElementById('idifr'))  )}catch(e){};
			 doll.fullscreen();	
	}
	if(event.keyCode===72){
		  
	    try{ 
		 
		window.jstoggle( document.getElementById('videolist') )
		if(window.locklist==true){
			window.locklist=false;
		window.setTimeout(function(){document.getElementById('videolist').style.display='none';
		window.locklist=true;},30000);
		}
		 }catch(e){console.log(warn)}	   
	}
	
	
	if(event.keyCode===74){
		  
	    try{ 
		 
		window.jstoggle( document.getElementById('videolist') )
		 }catch(e){console.log(warn)}	   
	}
	
	//N键随机播放，不重复
	if(event.keyCode===78){	  
	    try{ 
		window.randPlay();
		 }catch(e){ }	   
	}
		
	    if(event.keyCode!=82&&event.keyCode!=80&&event.keyCode!=82
		&&event.keyCode!=40&&event.keyCode!=38&&event.keyCode!=68&&
		event.keyCode!=69&&event.keyCode!=70&&event.keyCode!=72&&event.keyCode!=188&&
		event.keyCode!=190 && event.keyCode!=76 && event.keyCode!=77&& event.keyCode!=78){
	  tre.traceOne( 
		 '['+event.keyCode +'|'
		 +String.fromCharCode(event.keyCode)
		+"] F全屏 E退出全屏 P暂停播放 <快进 >快退 ↑音量加 ↓音量 "
		,false) 
		 
		}


	}
	
	
	)

    window.setInterval(function(){

        document.getElementById(oPlayer.progressID).style.width = progressIDWIDTH = Math.floor(
                (oPlayer.player().currentTime / oPlayer.player().duration)
                * window.innerWidth )+'px';
				
				window.g_paly_staus=' '+mathExt.to60(oPlayer.player().currentTime)
		+'/'+mathExt.to60(oPlayer.player().duration);
		try{
		   var BUF= oPlayer.player().buffered 
		//var valuebuf = 'BUF.start(0):'+BUF.start(BUF.length-1)+'|BUF.end(0):'+BUF.end(BUF.length-1)+'|BUF.length:'+BUF.length
		
		     document.getElementById(oPlayer.cacheID).style.width = Math.floor(
                ( BUF.end(BUF.length-1) / oPlayer.player().duration)
                * window.innerWidth  - parseInt (progressIDWIDTH) )+'px';
				
			document.getElementById(oPlayer.cacheID).style.left = progressIDWIDTH 
		}catch(e){
			console.warn(e)
			
			}

    },50)
    //TOOLS.mkDiv('mouseInfo','position:fixed;top:50px;color:#fff;background-color:red;','a')
    //$(window).on('mousemove',function(){
    //    document.getElementById('mouseInfo').innerHTML=TOOLS.getMousePagePos().join('<->')
    //})
    $(window).on('mousemove',function(){
            if(TOOLS.getMousePagePos()[1]>window.innerHeight-10){
               document.getElementById(oPlayer.ctrlerID).style.display = 'block'
            }
        if(TOOLS.getMousePagePos()[1]<=window.innerHeight-50){
            document.getElementById(oPlayer.ctrlerID).style.display = 'none'
        }
    })
   
    window.DkeyClick=function(){
		
		
		   var arr=['idfps' , 'info'];
		   for(k in arr){		 
		   var d = document.getElementById(arr[k]).style.display ;
		   document.getElementById(arr[k]).style.display = d!== 'none' ? 'none' : 'block';
		   }
		   window.sta.stop=!window.sta.stop
		   if(window.sta.stop===!true){
		       window.sta.runLoop();
		   }
		}

	
})

window.mkTrace=function (msg) {
    if (typeof window.mkTrace.boxismked === 'undefined') {
		//创建一装弹出杠的盒子，
		//如果创建了就不再创建
        window.mkTrace.boxismked = true;
        var box = document.createElement('div')
        window.mkTrace.boxid = '_boxid';//PLAYER.mkVideoId()+'_boxid'
        box.id = mkTrace.boxid;
        box.style.cssText = 'position:fixed;z-index:99;top:0px;'
        window.document.getElementsByTagName('body')[0].appendChild(box)
    }
	//创建一个弹出框
    var oDiv = document.createElement('div');
    oDiv.innerHTML = msg;
    oDiv.style.cssText = 'z-index:99;color:#fff; background-color:red;'
        +'width:'+window.innerWidth+'px;font-size:48px;margin-bottom:5px;'
        +' border-radius: 5px;filter: alpha(opacity = 50);opacity: 0.5; '
    document.getElementById(window.mkTrace.boxid).appendChild(oDiv)
    window.setTimeout(function(){oDiv.parentNode.removeChild(oDiv );	},10000)

}



var lib=(function(){
var PLAYER=function(){}
	PLAYER.fn             = PLAYER.prototype;
 	PLAYER.fn.constructor = PLAYER;		
	window.SSSS          = PLAYER;
			
})()
